import { getStorage } from './utils.js';
module.exports = (params) => {
	let url = `http://47.104.203.80:8888${params.url}`;	
	let method = params?.isPost ? "POST" : "GET";	
	let header = params.header || {};	
	let data = params.data || {};	
	
	// if	(!method) {
	// 	method = "POST"
	// }else{
	// 	method = "GET"
	// }
	
	var xt = 'x-token'
	header[xt] = getStorage() || ''
	
	console.log(header,'headerheaderheaderheaderheader')
	console.log(data, 'datdatdatda')
	
	//	发起网络请求
	if(!params.url){return}
	
	return new Promise( (resolve,reject) => {
		uni.request({
			url:url,
			method:method || "GET",
			header:header,
			data:data,
			dataType:"json",
			sslVerify:false,	//	是否验证ssl证书
			success: res => {
				
				console.log(res,'======')
				
				if	(res.statusCode && res.statusCode != 200){
					uni.showToast({
						title:'服务器出了一些问题~',
						icon:'none'
					})
					return;
				}
				
				resolve(res.data)
				
			},
			fail: err => {
				console.log(err,'err')
				reject(err)
			}
		})
		
	} )
	
}